/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).ready(function() 
{
    $(window).resize(
        function()
        {
            $('div.popUpBackground').css("height",$(document).height());
            $('div.popUpBackground').css("width",$(document).width());
            $('.discussionPopUp').css("top", ($(window).height() - $('.discussionPopUp').outerHeight()) / 2 + $(window).scrollTop() + "px");
            $('.discussionPopUp').css("left", ($(window).width() - $('.discussionPopUp').outerWidth()) / 2 + $(window).scrollLeft() + "px");
        }
    );
    $('.discussion').mouseover
    (
        function() 
        {
            $(this).css('cursor','pointer');
            $(this).css("background-color", "#aaaaaa");
        }

    );
    $('.discussion').mouseleave
    (
        function() 
        {
            $(this).css('cursor','pointer');
            $(this).css("background-color", "");
        }

    );
    $('.discussion').click
    (
        function() 
        {
            var value = $('#idForm'+$(this).attr('id')).attr('value');
            var name = $('#idForm'+$(this).attr('id')).attr('name');
            
            $(this).parent().attr('action','./Discussion');
            $(this).parent().html('<input type="hidden" name="'+name+'" value="'+value+'"/>');
            $('#form').submit();
        }
    ); 
    $('div.btnDiscussion').mouseover
    (
        function() 
        {
            $(this).css('cursor','pointer');
            $(this).css("background-color", "#444444");
            $(this).css("color", "#4f0000")
        }
    );         
    $('div.btnDiscussion').mouseleave
    (
        function() 
        {
            $(this).css('cursor','pointer');
            $(this).css("background-color", "#000000");
            $(this).css("color", "#ffffff")
        }
    );
    $('div.closePopUp').hover
    (
        function() 
        {
            $(this).css('cursor','pointer');
        }
    );
    $('div.closePopUp').click
    (
        function() 
        {
            $('div.popUpBackground').css("z-index","-1");
            $('div.popUpBackground').fadeOut("slow");
            $('div.discussionPopUp').fadeOut("slow");
        }
    );
    $('#btnNouvDiscussion').click(
        function()
        {
            if($('.popUpTitle').attr('value').length > 0 && $('.popUpMessage').attr('value').length > 0)
            {
                $(this).parent().submit();
            }
            if($('.popUpTitle').attr('value').length == 0)
            {
                $('.popUpTitle').addClass('invalide');
            }
            else
            {
                $('.popUpTitle').removeClass('invalide');
            }
            if($('.popUpMessage').attr('value').length == 0)
            {
                $('.popUpMessage').addClass('invalide');
            }
            else
            {
                $('.popUpMessage').removeClass('invalide');
            }
        }
    );
    $('.btnDiscussion').click
    (
        function() 
        {
            if($(this).attr("id")=="add"){
                $('div.popUpBackground').css("height",$(document).height());
                $('div.popUpBackground').css("width",$(document).width());
                $('div.popUpBackground').css("z-index","2");
                $('div.popUpBackground').fadeIn("slow");
                $('#addPopUp').css("top", ($(window).height() - $('#addPopUp').outerHeight()) / 2 + $(window).scrollTop() + "px");
                $('#addPopUp').css("left", ($(window).width() - $('#addPopUp').outerWidth()) / 2 + $(window).scrollLeft() + "px");
                $('#addPopUp').fadeIn("slow");
            }
            else if ($(this).attr("id")=="move"){
                var nbrSelected = 0;
                $('.chkDiscussion').each(
                    function()
                    {
                        if(this.checked)
                        {
                            ++nbrSelected;
                        }
                    }
                );
                if(nbrSelected == 0)
                {                    
                }
                else
                {
                    $('#formMove').html('<input type="hidden" name="'+$('#idSousSection').attr('name')+'" value="'+$('#idSousSection').attr('value')+'"/><span style="display:block;">'+$('#moveHead').html()+'</span>');
                    $('.chkDiscussion').each(
                        function()
                        {
                            if(this.checked)
                            {
                                var id = $(this).parent().prev('input').attr('value');
                                var title = $(this).parent().next('span.discussion').children('div.discussion-title').html();
                                $('#formMove').append('<span style="display:block;"> <input type="hidden" name="'+$('.idForm').attr('name')+'" value="'+id+'"/> <div class="colTitre tailleMoyen">'+title+'</div> <div class="colSelect"> <select name="'+id+'">'+$('#selectSousSection').html()+'</select> </div> </span>');
                            }
                        }
                    );
                    $('#formMove').append($('#submitButton').html());
                    $('div.popUpBackground').css("height",$(document).height());
                    $('div.popUpBackground').css("width",$(document).width());
                    $('div.popUpBackground').css("z-index","2");
                    $('div.popUpBackground').fadeIn("slow");
                    $('#movePopUp').css("top", ($(window).height() - $('#movePopUp').outerHeight()) / 2 + $(window).scrollTop() + "px");
                    $('#movePopUp').css("left", ($(window).width() - $('#movePopUp').outerWidth()) / 2 + $(window).scrollLeft() + "px");
                    $('#movePopUp').fadeIn("slow");
                }
            }
            else if ($(this).attr("id")=="delete"){
                nbrSelected = 0;
                $('.chkDiscussion').each(
                    function()
                    {
                        if(this.checked)
                        {
                            ++nbrSelected;
                        }
                    }
                );
                if(nbrSelected == 0)
                {                    
                }
                else
                {
                    confirmeSupp = false;
                    confirmeSupp = confirm($('#deleteDialog').html());
                    if(confirmeSupp)
                    {
                        $('#form').attr("action","./SupprimerDiscussion");
                        $('#form').attr("method","post");
                        $('#form').submit();
                    }
                }
            }
            else if ($(this).attr("id")=="lock"){
                nbrSelected = 0;
                $('.chkDiscussion').each(
                    function()
                    {
                        if(this.checked)
                        {
                            ++nbrSelected;
                        }
                    }
                );
                if(nbrSelected == 0)
                {                    
                }
                else
                {
                    $('#formLock').html('<input type="hidden" name="'+$('#idSousSection').attr('name')+'" value="'+$('#idSousSection').attr('value')+'"/><span style="display:block;">'+$('#lockHead').html()+'</span>');
                    $('.chkDiscussion').each(
                        function()
                        {
                            if(this.checked)
                            {
                                var id = $(this).parent().prev('input').attr('value');
                                var title = $(this).parent().next('span.discussion').children('div.discussion-title').html();
                                $('#formLock').append('<span style="display:block;"> <input type="hidden" name="'+$('.idForm').attr('name')+'" value="'+id+'"/> <div class="colTitre tailleMoyen">'+title+'</div> <div class="colSelect"> <select name="'+id+'">'+$('#selectLock').html()+'</select> </div> </span>');
                            }
                        }
                    );
                    $('#formLock').append($('#submitButton').html());
                    $('div.popUpBackground').css("height",$(document).height());
                    $('div.popUpBackground').css("width",$(document).width());
                    $('div.popUpBackground').css("z-index","2");
                    $('div.popUpBackground').fadeIn("slow");
                    $('#lockPopUp').css("top", ($(window).height() - $('#lockPopUp').outerHeight()) / 2 + $(window).scrollTop() + "px");
                    $('#lockPopUp').css("left", ($(window).width() - $('#lockPopUp').outerWidth()) / 2 + $(window).scrollLeft() + "px");
                    $('#lockPopUp').fadeIn("slow");
                }
            }
        }
    );
    $('div.popUpBackground').click
    (
        function()
        {
            $('div.popUpBackground').css("z-index","-1");
            $('div.popUpBackground').fadeOut("slow");
            $('div.discussionPopUp').fadeOut("slow");
        }
    );
    $('#navigation a').mouseover
    (
        function()
        {
            if($(this).attr("id")=="hover"){
                $(this).css("color","#4f0000");
                $('#hoverRoot').css("height",$(this).height());
                $('#hoverRoot').css("width",$(this).width());
                $('#hoverRoot').css("top",$(this).position().top);
                $('#hoverRoot').css("left",$(this).position().left);
                $('#hoverRoot').css("z-index","3");
                $('#hoverRoot').fadeIn("fast");
                $('#hoverBg').css("height",$(document).height());
                $('#hoverBg').css("width",$(document).width());
                $('#hoverBg').fadeIn("fast");
                $('#hoverBg').css("z-index","2");
            }
        }
    );
    $('#hoverBg').mouseover(
        function()
        {
            $('#hover').css("color","#ffffff");
            $('.hoverMenu').css("display","none");
            $('#hoverRoot').css("display","none");
            $('#hoverBg').css("z-index","-1");
            $('#hoverRoot').css("z-index","-1");
            $('#hoverBg').css("display","none");
        }
    );
    $('#hoverRoot').click(
        function()
        {
            $(this).children('form').submit();
        }
    );
});

